package iPod;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;

import sun.text.normalizer.UTF16;

public class DataObject extends IDBChunk
{	
	// Valid data types:
	public static final int TITLE = 1;
	public static final int LOCATION = 2;
	public static final int ALBUM = 3;
	public static final int ARTIST = 4;
	public static final int GENRE = 5;
	
	// Data stored in this object:
	protected int dataType = 0;
	protected String stringValue = "";
	
	public DataObject()
	{
		expectedID = "mhod";
	}
	
	public void loadChildren(RandomAccessFile in) throws Exception
    {
		// No children of a MHOD
    }
	
	public void loadHeader(RandomAccessFile in) throws Exception
    { 
		super.loadHeader(in);
		
		// Load extra database information:
		// Load the type of data stored
		in.read(item);
		dataType = DataUtils.littleEndianToInt(item);
		
		if (dataType < 15)
		{
			// Load the length of the string
			in.seek(startPos + 28);
			in.read(item);
			int stringLength = DataUtils.littleEndianToInt(item);
			
			// Load the string
			in.seek(startPos + 40);
			byte string[] = new byte[stringLength];
			in.read(string);
			stringValue = new String(string, Charset.forName("UTF-16LE"));
		}
    }

	public int getDataType() {
		return dataType;
	}

	public String getStringValue() {
		return stringValue;
	}
}
